package com.region.plugin.proxy.cglib;

import com.region.plugin.Interceptor;
import com.region.plugin.proxy.AbstractRealProxy;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author 26225
 * @date 2024/9/7 13:40
 * @description
 */
public class CglibRealProxy extends AbstractRealProxy implements MethodInterceptor {

    public CglibRealProxy(Object target, Interceptor interceptor) {
        super(target, interceptor);
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        if (Object.class.equals(method.getDeclaringClass())) {
            // If it's a method of the object class just run it
            return methodProxy.invokeSuper(o, objects);
        } else {
            return executeProceed(interceptor, new CglibProceedPoint(target, objects, methodProxy));
        }
    }
}
